package edu.thu.studio.ormdesigner.outline.action;

import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.PlatformUI;

import edu.thu.studio.ormdesigner.outline.command.CreateDomainCommand;
import edu.thu.studio.ormdesigner.outline.dialog.DomainDialog;
import edu.thu.studio.ormdesigner.util.Properties;

public class CreateDomainAction extends AbstractOutlineAction {
    
    public static final String ID = CreateDomainAction.class.getName();
    
    public CreateDomainAction(TreeViewer treeViewer) {
        super(ID, Properties.outline_menu_create_domain, treeViewer);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public void execute(Event event) {
        
        DomainDialog dialog = new DomainDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null,
            this.getORMModel());
        
        if (dialog.open() == IDialogConstants.OK_ID) {
            CreateDomainCommand command = new CreateDomainCommand(this.getORMModel(), dialog.getResult());
            this.execute(command);
        }
    }
    
}
